import GlobalHeader from '@/components/GlobalHeader';
import PageHeader from '@/components/PageHeader';
import SiderMenu from '@/components/SiderMenu';
import uploadImg from '@/components/uploadImg';
import LimitInput from '@/components/LimitInput';
import MedGatewayPagination from '@/components/pagination';
import ICountUp from 'vue-countup-v2';

export default Vue => {
  // 注册 components
  Vue.component('GlobalHeader', GlobalHeader);
  Vue.component('PageHeader', PageHeader);
  Vue.component('SiderMenu', SiderMenu);
  Vue.component('UploadImg', uploadImg);
  Vue.component('LimitInput', LimitInput);
  Vue.component('MedGatewayPagination', MedGatewayPagination);
  Vue.component('ICountUp', ICountUp);

  Vue.component('RemoteScript', {
    props: {
      src: {
        type: String,
        required: true,
      },
      beforeRender: {
        type: Function,
        default: null,
      },
    },

    render: function(createElement) {
      var self = this;
      this.beforeRender && typeof this.beforeRender === 'function' && this.beforeRender();
      return createElement('script', {
        attrs: {
          type: 'text/javascript',
          src: this.src,
        },
        on: {
          load: function(event) {
            self.$emit('load', event);
          },
          error: function(event) {
            self.$emit('error', event);
          },
        },
      });
    },
  });
};
